#!/bin/bash

fd_install_source=/usr/local/software

target_file=/etc/profile

home=/niuniu/tools/maven


mkdir -pv ${home}

cd ${home}


rm -rf ./*

tar -zxvf ${fd_install_source}/apache-maven-3.3.9-bin.tar.gz

fd_target_item=`ls -l | grep maven | awk '{print $NF}'`

# 移除 maven 环境配置 


sed -i '/^# maven Environment config/d'  $target_file
sed -i '/^export MAVEN_HOME=/d'  $target_file
sed -i '/^export PATH=\$MAVEN_HOME/d'  $target_file


# 配置 maven 环境变量


echo "# maven Environment config begin " >> $target_file

echo "export MAVEN_HOME=${home}/${fd_target_item}" >> $target_file
echo "export PATH=\$MAVEN_HOME/bin:\$PATH" >> $target_file

echo "# maven Environment config end " >> $target_file

source $target_file

mvn -v
